@extends('home.parent')
@section('title','合伙人列表')
@section('head_js')
@endsection
@section('head_css')
<link rel="stylesheet" href="{{ asset('/css/dataTables.bootstrap.css') }}">
<link rel="stylesheet" href="{{ asset('/css/toggleButtonsMain.css') }}">
@endsection
@section('content')
  <div class="content-wrapper">
    <section class="content-header">
      <h1>
        合伙人列表
        <small></small>
      </h1>
      <ol class="breadcrumb">
        <li><a href="{{URL('admin')}}"><i class="fa fa-dashboard"></i> 首页</a></li>
        <li class="active">合伙人列表</li>
      </ol>
    </section>
    <section class="content">
      <div class="row">
        <div class="col-xs-12">
          <div class="box">
            <div class="box-header">
              <div class="form-inline pull-right">
                <fieldset>
                  <div class="input-group input-group-sm">
                    <span class="input-group-addon"><strong>用户名</strong></span>
                    <input type="text" class="form-control" id="user_name">
                  </div>
                  <div class="input-group input-group-sm">
                    <span class="input-group-addon"><strong>机构</strong></span>
                    <input type="text" class="form-control" id="company">
                  </div>
                  <div class="input-group input-group-sm">
                    <span class="input-group-addon"><strong>联系人</strong></span>
                    <input type="text" class="form-control" id="search_name">
                  </div>
                  <div class="input-group input-group-sm">
                    <span class="input-group-addon"><strong>手机号码</strong></span>
                    <input type="text" class="form-control" id="search_mobile">
                  </div>
                  <div class="input-group input-group-sm">
                    <div class="input-group-btn">
                      <button type="button"  class="btn btn-primary" onclick="searchData()"><i class="fa fa-search"></i></button>
                    </div>
                  </div>
                </fieldset>
              </div>
              <div class="form-inline pull-left">
                <div class="input-group input-group-sm" style="margin-left: 20px;">
                  <div class="input-group-btn" >
                    <a href="{{ URL('admin/partner/create') }}" class="btn btn-info">新增合伙人</a>
                  </div>
                </div>
              </div>
            </div>
            <!-- /.box-header -->
            <div class="box-body">
              <table id="data_list" class="table table-bordered table-striped">
                <thead>
                  <tr>
                    <th>编号</th>
                      <th>创建者</th>
                    <th>用户名</th>
                    <th>地区</th>
                    <th>合伙机构</th>
                    <th>联系人</th>
                    <th>性别</th>
                    <th>联系方式</th>
                    <th>操作时间</th>
                    <th>实名</th>
                    <th>会员人数</th>
                    <th>状态</th>
                    <th>操作</th>
                  </tr>
                </thead>
                <tbody>
                </tbody>
                <tfoot>
                  <tr>
                    <th>编号</th>
                      <th>创建者</th>
                    <th>用户名</th>
                    <th>地区</th>
                    <th>合伙机构</th>
                    <th>联系人</th>
                    <th>性别</th>
                    <th>联系方式</th>
                    <th>操作时间</th>
                      <th>实名</th>
                    <th>会员人数</th>
                    <th>状态</th>
                    <th>操作</th>
                  </tr>
                </tfoot>
              </table>
            </div>
          </div>
        </div>
      </div>
    </section>
  </div>
<div class="modal fade" id="viewDetails">
	<div class="modal-dialog">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-label="Close">
				<span aria-hidden="true">&times;</span></button>
				<h4 class="modal-title">某某用户详情</h4>
			</div>
			<div class="modal-body" style="max-height:300px;overflow:auto;padding:10px 100px;"></div>
		</div>
	</div>
</div>
  <style>
      #shoucang table {
          border-collapse: collapse;
          color: #777;
          width: 100%;
      }

      #shoucang table tr th, #tableComment table tr td {
          padding: 10px;
          border: 1px solid #f8f8f8;
          white-space: nowrap
      }

      #shoucang table tbody tr:hover {
          background: #f3f3f3;
      }

      #shoucang table thead tr {
          background: #f0f0f0;
      }

      #shoucang .more {
          text-align: center;
          padding: 10px 0;
      }

      #shoucang .more span {
          cursor: pointer;
      }

      #shoucang div button {
          padding-right: 20px;
          margin-right: 15px;
      }
  </style>
  <div id="shoucang" style="display:none;color:#777;padding:10px 20px 0 20px;">
      <table>
          <thead>
          <tr>
              <td>用户名</td>
              <td>地区</td>
              <td>会员机构</td>
              <td>行业</td>
              <td>联系人</td>
              <td>性别</td>
              <td>联系方式</td>
              <td>实名情况</td>
              <td>状态</td>
              <td>操作</td>
          </tr>
          </thead>
          <tbody></tbody>
      </table>
      <div class="more"></div>
  </div>
<style>
	#charging div.modal-body p{margin-top:20px;}
	#charging div.modal-body p.xuanzhe{margin-top:0;}
	#charging div.modal-body p.spen3{display:none;}
	#charging div.modal-body p.error_msg{display:none;color:red;font-size:14px;font-weight:600;}
	#charging div.modal-body p span{padding:8px 10px;border:1px solid #ddd;cursor:pointer;}
	#charging div.modal-body span.active{background-color:#ddd;color:#fff;cursor:default;}
</style>
<div class="modal fade" id="charging">
	<div class="modal-dialog">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-label="Close">
				<span aria-hidden="true">&times;</span></button>
				<h4 class="modal-title">合伙人充值</h4>
			</div>
			<div class="modal-body" style="max-height:300px;overflow:auto;">
				<p class="xuanzhe"><span class="active" onclick="checkSpan(this,1)">默认</span><span onclick="checkSpan(this,2)">手动</span><span onclick="checkSpan(this,3)">减额</span></p>
				<p class="span span0"><label>充值金额：<input type="text" name="price" value=""></label></p>
				<p class="span spen1"><label>充值比例：<input type="text" name="discount" value="{{ $partner_discount }}" disabled></label></p>
				<p class="span spen2"><label>实际金额：<input type="text" name="actualPrice" value="" disabled></label></p>
				<p class="span spen3"><label>扣除金额：<input type="text" name="deductPrice" value="" disabled></label></p>
				<input type="hidden" name="kid">
				<input type="hidden" name="type" value="1">
				<p class="error_msg"></p>
			</div>
			<div class="modal-footer">
				<button type="button" class="btn btn-default pull-left" data-dismiss="modal">关闭</button>
				<button type="button" class="btn btn-primary saveCharging" onclick="saveCharging()">保存</button>
			</div>
		</div>
	</div>
</div>
<style>
#Deck .form-control{
	width:280px;
	color:#777;
}
#Deck table tr td{
	color:#777;
	padding: 5px 10px;
	border: 1px solid transparent;
	white-space: nowrap;
}
#Deck table tr td.small{
	color: #FF6666;
}
#Deck textarea{
	resize:none;
}
#Deck input[type="file"]{
	display:none;
}
#uploadImg{
	max-width: 120px;
	max-height: 120px;
	cursor: pointer;
}
#uploadIcon{
	max-width:64px;
	max-height:64px;
	cursor:pointer;
}
#delImg,#delIcon{
	display:none;
	margin-left:20px;
}
</style>
<div id="Deck" style="padding:10px;display:none;">
	<table>
	<form class="qiniuUploadForm" method="post" enctype="multipart/form-data">
		<tr>
			<td>网站名称：</td>
			<td><input type="text" class="form-control" name="title" placeholder="网站名称" maxlength="10"></td>
		</tr>
		<tr><td class="small" colspan="10">网站名称如：云快视</td></tr>
		<tr>
			<td>官网链接：</td>
			<td><textarea type="text" class="form-control" name="url" placeholder="官网链接" maxlength="255"></textarea></td>
			
		</tr>
		<tr><td class="small" colspan="10">官网链接如：http://www.baidu.com</td></tr>
		<tr>
			<td>后缀：</td>
			<td><input type="text" class="form-control" name="deck" placeholder="后缀" maxlength="100"></td>
			<td><a href="javascript:;" class="btn btn-info btn-sm" onclick="random()">随机生成</a></td>
		</tr>
		<tr><td class="small" colspan="10">合伙人登录地址：{{ $_ENV['PARNTER_URL'] }}/admin/login?deck=后缀</td></tr>
		<tr><td class="small" colspan="10">会员登录地址：{{ $_ENV['VIP_URL'] }}/admin/login?deck=后缀</td></tr>
		<tr>
			<td>网站logo：</td>
			<td>
				<div>
					<img src="/img/sc.png" id="uploadImg">
					<input type="file" name="img" id="deckImg" onchange="deckImgChange(this)">
					<a href="javascript:;" class="btn btn-info btn-sm" id="delImg">移出</a>
				</div>
			</td>
		</tr>
		<tr><td class="small" colspan="10">logo不能大于1M，只支持png、jpg</td></tr>
		<tr>
			<td>网站图标：</td>
			<td>
				<div>
					<img src="/img/sc.png" id="uploadIcon">
					<input type="file" name="icon" id="deckIcon" onchange="deckIconChange(this)">
					<a href="javascript:;" class="btn btn-info btn-sm" id="delIcon">移出</a>
				</div>
			</td>
		</tr>
		<tr><td class="small" colspan="10">icon不能大于1M，最大尺寸：128px * 128px</td></tr>
		<input type="hidden" name="kid">
		<input type="hidden" name="oldImg">
		<input type="hidden" name="oldIcon">
	</form>
	</table>
</div>
  <div class="modal fade" id="taldataform">
      <div class="modal-dialog">
          <div class="modal-content">
              <form id="dataform">
                  <div class="modal-header">
                      <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                          <span aria-hidden="true">&times;</span></button>
                      <h4 class="modal-title">某某用户套餐详情</h4>
                  </div>
                  <div class="modal-body" style="max-height:300px;overflow:auto;padding:0 15px;">
                      <table class="table table-bordered table-striped">
                          <thead>
                          <tr>
                              <td width="100px">套餐名称</td>
                              <td>套餐日期</td>
                              <td>套餐金额</td>
                              <td>套餐内容</td>
                          </tr>
                          </thead>
                          <tbody>
                          <tr>
                              <td colspan="6">22</td>
                          </tr>
                          </tbody>
                      </table>
                  </div>
              </form>
          </div>
      </div>
  </div>
  <div class="modal fade" id="viewDetails">
      <div class="modal-dialog">
          <div class="modal-content">
              <div class="modal-header">
                  <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                      <span aria-hidden="true">&times;</span></button>
                  <h4 class="modal-title">某某用户详情</h4>
              </div>
              <div class="modal-body" style="max-height:300px;overflow:auto;padding:10px 100px;"></div>
          </div>
      </div>
  </div>
@endsection
@section('foot_js')
<script src="{{ asset('/js/jquery.dataTables.min.js') }}"></script>
<script src="{{ asset('/js/dataTables.bootstrap.min.js') }}"></script>
<script src="{{ asset('/js/jquery.slimscroll.min.js') }}"></script>
<script src="{{ asset('/js/fastclick.js') }}"></script>
<script src="{{ asset('/js/tools.js') }}"></script>
<script src="{{ asset('/js/md5.min.js') }}"></script>
<script>
var list_ajax;
$(function () {
  //提示信息
  var lang = puppet.langShow();
  //初始化表格
  list_ajax = $("#data_list").dataTable({
    language: lang, //提示信息
    autoWidth: false, //禁用自动调整列宽
    stripeClasses: ["odd", "even"], //为奇偶行加上样式，兼容不支持CSS伪类的场合
    processing: true, //隐藏加载提示,自行处理;
    serverSide: true, //启用服务器端分页
    searching: false, //禁用原生搜索
    //"sSearch": "搜索:",
    orderMulti: false, //启用多列排序
    order: [[0, 'desc']], //取消默认排序查询,否则复选框一列会出现小箭头
    renderer: "bootstrap", //渲染样式：Bootstrap和jquery-ui
    pagingType: "simple_numbers", //分页样式：simple,simple_numbers,full,full_numbers
    aLengthMenu : [10, 20, 50, 100], //更改显示记录数选项
    iDisplayLength:10,
    columnDefs: [
      {
        "targets": [1,2,3,4,5,6,7,8,9,10,11], //列的样式名
        "orderable": false    //包含上样式名‘nosort’的禁止排序
      },
      {
        targets: 6,
        render: function (data, type, row, meta) {
          switch(data) {
            case 1:
              return '男';
              break;
            case 2:
              return '女';
              break;
            default:
              return '未知';
              break;
          }
        }
      },
      {
        targets: 11,
        render: function (data, type, row, meta) {
          switch(data) {
            case 1:
              return '<div class="checkbox checkbox-slider--b-flat"><label>'+
                  '<input type="checkbox" checked onclick="actionList(' + row.id + ',0)"><span></span></label></div>';
              break;
            case 0:
              return '<div class="checkbox checkbox-slider--b-flat"><label>'+
                  '<input type="default" onclick="actionList(' + row.id + ',1)"><span></span></label></div>';
              break;
            default:
              return '';
              break;
          }
        }
      },
      {
        targets: 12,
        render:function(data,type,row,meta){
          return  "<a href='javascript:;' title='查看' aria-label='View' data-pjax='0'><span class='glyphicon glyphicon-eye-open' onclick=\"viewInfo("+row.id+",'"+row.user_name+"')\"></span></a>&nbsp;&nbsp;&nbsp;&nbsp;"+
                  "<a href='{{ URL('admin/partner/edit') }}/"+row.id+"' title='修改' aria-label='Update' data-pjax='0'><span class='glyphicon glyphicon-pencil'></span></a>&nbsp;&nbsp;&nbsp;&nbsp;"+
				  "<a href='javascript:;' title='删除' aria-label='Delete' data-pjax='0'><span class=\"glyphicon glyphicon-trash\" onclick=\"actionList("+row.id+",-1)\"></span></a>&nbsp;&nbsp;&nbsp;&nbsp;"+
				  "<a href='javascript:;' title='充值' data-pjax='0'><span class=\"fa fa-money\" onclick=\"charging("+row.id+",'"+data.user_name+"')\"></span></a>&nbsp;&nbsp;&nbsp;&nbsp;"+
				  "<a href='javascript:;' title='贴牌' data-pjax='0'><span class=\"fa fa-navicon\" onclick=\"Deck("+row.id+",'"+data.user_name+"')\"></span></a>&nbsp;&nbsp;&nbsp;&nbsp;";
        }
      },
    ],
    ajax: function (data, callback, settings) {
      //封装请求参数
      var param = {};
      param.limit = data.length; //页面显示记录条数，在页面显示每页显示多少项的时候
      param.start = data.start; //开始的记录序号
      param.page = (data.start / data.length) + 1; //当前页码
      param.order = data.order;
      param.user_name = $.trim($("#user_name").val());
      param.name = $.trim($("#search_name").val());
      param.mobile = $.trim($("#search_mobile").val());
      param.company = $.trim($("#company").val());
      $.ajax({
        type: "POST",
        url: "{{ URL('admin/partner/list/ajax') }}",
        cache: false, //禁用缓存
        data: param, //传入组装的参数
        dataType: "json",
        success: function (result) {
          var returnData = {};
          returnData.draw = data.draw; //这里直接自行返回了draw计数器,应该由后台返回
          returnData.recordsTotal = result.total; //返回数据全部记录
          returnData.recordsFiltered = result.total; //后台不实现过滤功能，每次查询均视作全部结果
          returnData.data = result.data; //返回的数据列表
          callback(returnData);
        }
      });
    },
    //列表表头字段
    columns: [
      {"data": "kid"},
      {"data": "createname"},
      {"data": "user_name"},
      {"data": "city"},
      {"data": "company"},
      {"data": "name"},
      {"data": "gender"},
      {"data": "mobile"},
      {"data": "update_time"},
      {"data": "realname"},
      {"data": "vips"},
      {"data": "status"},
      {"data": null}
    ],
  }).api();
});
function actionList(id,status){
  var result;
  switch(status){
      case 0:
          result = layer.confirm('是否确认关闭', {
              btn: ['确认关闭', '再考虑一下'] //按钮
          }, function () {
              layer.msg('操作成功',{icon:1});
              xiugaihhr(id, status);
          },function () {
              list_ajax.ajax.reload(null,false);
          });
          break;
      case 1:
          result = layer.confirm('是否确认开启', {
              btn: ['确认开启', '再考虑一下'] //按钮
          }, function () {
              layer.msg('操作成功',{icon:1});
              xiugaihhr(id, status);
          },function () {
              list_ajax.ajax.reload(null,false);
          });
          break;
      case -1:
          result = layer.confirm('是否确认删除', {
              btn: ['确认删除', '再考虑一下'] //按钮
          }, function () {
              layer.msg('操作成功',{icon:1});
              xiugaihhr(id, status);
          });
          break;
      default:
          result = layer.confirm('是否确认删除', {
              btn: ['确认删除', '再考虑一下'] //按钮
          }, function () {
              xiugaihhr(id, status);
          });
          break;
  }
}
function xiugaihhr(id, status) {
    var url = "{{URL('admin/partner/delete')}}";
    var data = {id:id,status:status};
    var result = puppet.myajax('post',url,data,false);
    if(result.code == true){
        layer.msg(result.msg,{icon:2});
        return false;
    }else{
        list_ajax.ajax.reload(null,false);
    }
}
//查看对应会员的套餐
function mealList(kid,name){
    layer.closeAll();
    $('#taldataform').modal();
    $('#taldataform h4').html("<span style='font-weight:bold;'>"+name+"</span> 套餐详情");
    var data={kid:kid};
    var url = "{{URL('admin/vip/list/data')}}";
    var result = puppet.myajax('post',url,data,false);
    if(result.code == 1){
        layer.msg(result.message,{icon:5});
        return false;
    }else{
        $('#taldataform tbody').html(result.msg);
    }
}
//查看会员信息
function viewVip(kid,user_name){
    layer.closeAll();
    $('#viewDetails').modal();
    $('#viewDetails h4').html("<span style='font-weight:bold;'>"+name+"</span> 会员详情");
    var data={kid:kid};
    var url = "{{URL('admin/vip/view/info')}}";
    var result = puppet.myajax('post',url,data,false);
    if(result.code == 1){
        layer.msg(result.message,{icon:5});
        return false;
    }else{
        $('#viewDetails div.modal-body').html(result.msg);
    }
}
function searchData(){
  $("#data_list").dataTable().fnDraw(false);
  layer.msg('操作成功',{icon:6});
}
function viewInfo(kid,name){
	$('#viewDetails').modal();
	$('#viewDetails h4').html("<span style='font-weight:bold;'>"+name+"</span> 合伙人详情");
	var data={kid:kid};
	var url = "{{URL('admin/partner/view/info')}}";
	var result = puppet.myajax('post',url,data,false);
	if(result.code == 1){
        layer.msg(result.msg,{icon:2});
		return false;
	}else{
		$('#viewDetails div.modal-body').html(result.msg);
	}
}
//查询合伙人会员列表
function showvips(kid,name) {
    layer.closeAll();
    shoucang(kid,name)
    $('#shoucang tbody').html("");
    showlayerArea("shoucang", name, "80%", "80%");
}
function shoucang(kid,name) {
    $.ajax({
        type: 'POST',
        url: "{{ URL('admin/getvipinfo/data') }}",
        data: {kid: kid},
        dataType: 'json',
        success: function (r) {
            if (r.code == 1) {
                $('#shoucang tbody').html("<tr><td colspan=\"10\" style=\"text-align:center;\">无数据</td></tr>");
                layer.msg(r.msg, {icon: 5});
                return false;
            }else {
                $('#shoucang tbody').html(r.msg);
            }

        },
        error: function () {
            $('#shoucang tbody').html("<tr><td colspan=\"10\" style=\"text-align:center;\">无数据</td></tr>");
            layer.msg("网络错误", {icon: 5});
        }
    });
}
//合伙人充值
function charging(kid,userName){
	$('#charging input[name="kid"]').val(kid);
	$('#charging').modal();
	$('#charging div.modal-header h4').html("<font style=\"color:red;\">"+userName+"</font> 充值");
	$('#charging input[name="price"]').val('');
	$('#charging input[name="actualPrice"]').val('');
	$('#charging input[name="deductPrice"]').val('');
}
function checkSpan(obj,index){
	$('p.xuanzhe span').removeClass('active').css({"background-color":"#fff","color":"#333","cursor":"pointer"});
	$(obj).addClass('active').css({"background-color":"#ddd","color":"#fff","cursor":"default"});
	$('p.span').hide();
	$('#charging p.error_msg').html('').hide();
	if(index==1){//默认
		$('#charging input[name="type"]').val(1);
		$('p.span0').show();
		$('p.spen1').show();
		$('p.spen2').show();
		$('p.spen1 label input').attr('disabled',true);
		$('p.spen2 label input').attr('disabled',true);
		$('#charging input[name="price"]').val('');
		$('#charging input[name="actualPrice"]').val('');
	}else if(index==2){//手动
		$('#charging input[name="type"]').val(2);
		$('p.span0').show();
		$('p.spen2').show();
		$('p.spen2 label input').attr('disabled',false);
		$('#charging input[name="price"]').val('');
		$('#charging input[name="actualPrice"]').val('');
	}else if(index==3){//减额
		$('#charging input[name="type"]').val(3);
		$('p.spen3').show();
		$('p.spen3 label input').attr('disabled',false);
		$('#charging input[name="deductPrice"]').val('');
	}
}
$('#charging input[name="price"]').keyup(function(){
	checkPrice('price',1);
});
$('#charging input[name="actualPrice"]').keyup(function(){
	checkPrice('actualPrice',2);
});
$('#charging input[name="deductPrice"]').keyup(function(){
	checkPrice('deductPrice',3);
});
function checkPrice(inputName,checkType){
	if(checkType==1 || checkType==2){
		var price=$('#charging input[name="'+inputName+'"]').val();
		var type=$('#charging input[name="type"]').val();
		var discount=$('#charging input[name="discount"]').val();
		var check=/^[1-9]{1}[0-9]{0,}00$/;
		if(check.test(price)){
			if(type==1){
				num=(Number(discount)*Number(price)).toFixed(0);
				$('#charging input[name="actualPrice"]').val(num);
			}
			$('#charging p.error_msg').hide();
			return true;
		}else{
			if(checkType==1){
				$('#charging p.error_msg').html("充值金额：必须是100的倍数").show();
			}else{
				$('#charging p.error_msg').html("实际金额：必须是100的倍数").show();
			}
		}
	}else if(checkType==3){
		var price=$('#charging input[name="'+inputName+'"]').val();
		var check=/^[1-9]{1}[0-9]{0,}$/;
		if(check.test(price)){
			$('#charging p.error_msg').hide();
			return true;
		}else{
			$('#charging p.error_msg').html("扣除金额：请输入正确的金额数（正整数）").show();
		}
	}

	return false;
}
function saveCharging(){
	var yesNo=false;
	var data="";
	var type=$('#charging input[name="type"]').val();
	if(type==1){
		yesNo=checkPrice('price',1);
		price=$('#charging input[name="price"]').val();
		data="type="+type+"&price="+price;
	}else if(type==2){
		yesNo=checkPrice('price',1);
		if(yesNo==true){yesNo=checkPrice('actualPrice',2);}
		price=$('#charging input[name="price"]').val();
		actualPrice=$('#charging input[name="actualPrice"]').val();
		data="type="+type+"&price="+price+"&actualPrice="+actualPrice;
	}else if(type==3){
		yesNo=checkPrice('deductPrice',3);
		price=$('#charging input[name="deductPrice"]').val();
		data="type="+type+"&price="+price;
	}
	if(yesNo==true){
		var data="kid="+$('#charging input[name="kid"]').val()+"&"+data;
		// console.log(data);
		var url = "{{URL('admin/partner/save/charging')}}";
		var result = puppet.myajax('post',url,data,false);
		if(result.code == 1){
            layer.msg(result.msg,{icon:2});
			return false;
		}else{
            layer.msg(result.msg,{icon:1});
			$('#charging').modal('hide');
		}
	}
}
//-------------------------------------------------------------------------------------------
//打开贴牌管理
function Deck(kid,name){
	$('#deckImg').val('');
	$('#deckIcon').val('');
	$('#delImg').hide();
	$('#delIcon').hide();
	$.ajax({
		type:'POST',
		url: "{{ URL('partner/deck/list') }}",
		data: {kid:kid},
		dataType:'json',
		success:function(r){
			if(r.msg!=''){
				$('#Deck input[name="title"]').val(r.msg.title);
				$('#Deck textarea[name="url"]').val(r.msg.url);
				$('#Deck input[name="deck"]').val(r.msg.deck);
				$('#Deck input[name="kid"]').val(kid);
				
				
				$('#Deck input[name="oldImg"]').val(r.msg.img);
				if(r.msg.img!='' && r.msg.img!=null){
					$('#uploadImg').attr('src',r.msg.img);
				}else{
					$('#uploadImg').attr('src','/img/sc.png');
				}
				
				
				$('#Deck input[name="oldIcon"]').val(r.msg.icon);
				if(r.msg.icon!='' && r.msg.icon!=null){
					$('#uploadIcon').attr('src',r.msg.icon);
				}else{
					$('#uploadIcon').attr('src','/img/sc.png');
				}
			}else{
				$('#Deck input,#Deck textarea').val('');
				$('#Deck img').attr('src','/img/sc.png');
				$('#Deck input[name="kid"]').val(kid);
			}
		},
		error:function(){
			layer.msg("网络错误",{icon: 5});
		}
	});
	showlayerOne("Deck","贴牌管理账户："+name,saveDeck,false);
}
//点击图片选择触发选择图片控件
$('#uploadImg').click(function(){
	$('#deckImg').click();
});
$('#uploadIcon').click(function(){
	$('#deckIcon').click();
});
//随机生成后缀
function random(){
	var kid=$('#Deck input[name="kid"]').val();
	var mydate = new Date();
	var string=md5(kid+mydate.getTime());
	$('#Deck input[name="deck"]').val(string);
}
//图片发生改变时
function deckImgChange(obj){
	if($(obj)[0].files[0]=='' || $(obj)[0].files[0]==null || $(obj)[0].files[0]==undefined || $(obj)[0].files[0]=='NaN'){
		var oldImg=$('#Deck input[name="oldImg"]').val();
		if(oldImg!='' && oldImg!=null){
			$('#uploadImg').attr('src',oldImg);
		}else{
			$('#uploadImg').attr('src','/img/sc.png');
		}
		$('#delImg').hide();
		return false;
	}
	var this_img=puppet.getObjectURL(obj);
	if ($(obj)[0].files[0]['type'] != 'image/pjpeg' && $(obj)[0].files[0]['type'] != 'image/jpeg' && $(obj)[0].files[0]['type'] != 'image/png' && $(obj)[0].files[0]['type'] != 'image/x-png') {
		layer.msg('logo格式错误', {icon: 5});
	}else if ($(obj)[0].files[0]['size'] > 1048576) {
		layer.msg ('logo不能大于1M', {icon: 5});
		$('#deckImg').val('');
	} else {
		$('#uploadImg').attr('src',this_img);
		$('#delImg').show();
	}
}
function deckIconChange(obj){
	if($(obj)[0].files[0]=='' || $(obj)[0].files[0]==null || $(obj)[0].files[0]==undefined || $(obj)[0].files[0]=='NaN'){
		var oldIcon=$('#Deck input[name="oldIcon"]').val();
		if(oldIcon!='' && oldIcon!=null){
			$('#uploadIcon').attr('src',oldIcon);
		}else{
			$('#uploadIcon').attr('src','/img/sc.png');
		}
		$('#delIcon').hide();
		return false;
	}
	var this_icon=puppet.getObjectURL(obj);
	if ($(obj)[0].files[0]['type'] != 'image/x-icon') {
		layer.msg('icon格式错误', {icon: 5});
	}else if ($(obj)[0].files[0]['size'] > 1048576) {
		layer.msg ('icon不能大于1M', {icon: 5});
		$('#deckIcon').val('');
	} else {
		$('#uploadIcon').attr('src',this_icon);
		$('#delIcon').show();
	}
}
//移除选择的图片
$('#delImg').click(function(){
	var oldImg=$('#Deck input[name="oldImg"]').val();
	if(oldImg!=''){
		$('#uploadImg').attr('src',oldImg);
	}else{
		$('#uploadImg').attr('src','/img/sc.png');
	}
	$('#deckImg').val('');
	$('#delImg').hide();
});
$('#delIcon').click(function(){
	var oldIcon=$('#Deck input[name="oldIcon"]').val();
	if(oldIcon!=''){
		$('#uploadIcon').attr('src',oldIcon);
	}else{
		$('#uploadIcon').attr('src','/img/sc.png');
	}
	$('#deckIcon').val('');
	$('#delIcon').hide();
});

//保存贴牌
function saveDeck(){
	var data = new FormData();
	data.append("kid",$('#Deck input[name="kid"]').val());
	data.append("title",$('#Deck input[name="title"]').val());
	data.append("url",$('#Deck textarea[name="url"]').val());
	data.append("deck",$('#Deck input[name="deck"]').val());
	data.append("oldImg",$('#Deck input[name="oldImg"]').val());
	data.append("oldIcon",$('#Deck input[name="oldIcon"]').val());
	data.append("deckImg", $('#deckImg')[0].files[0]);
	data.append("deckIcon", $('#deckIcon')[0].files[0]);
	$.ajax({
		type:'POST',
		url: "{{ URL('partner/deck/save') }}",
		data: data,
		dataType:'json',
		cache: false,//上传文件无需缓存
		processData: false,//用于对data参数进行序列化处理 这里必须false
		contentType: false, //必须
		beforeSend:function(){
			loading_show();
		},
		success:function(r){
			loading_hidden();
			if(r.code==0){
				layer.closeAll();
				layer.msg(r.msg,{icon: 6});
			}else{
				layer.msg(r.msg,{icon: 5});
			}
		},
		error:function(){
			loading_hidden();
			layer.msg("网络错误",{icon: 5});
		}
	});
}
</script>
@endsection